package com.lan.support.page;


import java.util.Date;

public class PageHelper {

    private Integer curPage = 1;

    private Integer pageSize = 10;

    private Date startTime;

    private Date endTime;

    /**
     * 排序
     */
    private String sortName;
    /**
     * 默认升序
     */
    private String sortOrder = "DESC";

    /**
     * 是否查询总记录数
     */
    private Boolean countable = true;

    public Paging page;


    public PageHelper() {

    }

    public PageHelper(Integer curPage, Integer pageSize) {
        this.curPage = curPage;
        this.pageSize = pageSize;
    }


    /**
     * 但前偏移量开始
     *
     * @return
     */
    public Integer start() {
        Integer curPage = getCurPage();
        if (curPage == null) {
            return 0;
        } else {
            if (curPage <= 1) {
                curPage = 1;
            }
            return (curPage - 1) * getPageSize();
        }
    }


    public Integer getPageSize() {
        if (pageSize == null) {
            pageSize = 10;
        }
        return pageSize;
    }


    public Paging getPage() {
        Paging page = new Paging();
        page.setStart(start());
        page.setPageSize(getPageSize());
        page.setSortName(sortName);
        page.setSortOrder(sortOrder);
        page.setStartTime(startTime);
        page.setEndTime(endTime);
        return page;
    }

    public Integer getCurPage() {
        return curPage;
    }

    public void setCurPage(Integer curPage) {
        this.curPage = curPage;
    }

    public void setPageSize(Integer pageSize) {
        this.pageSize = pageSize;
    }

    public String getSortName() {
        return sortName;
    }

    public void setSortName(String sortName) {
        this.sortName = sortName;
    }

    public String getSortOrder() {
        return sortOrder;
    }

    public void setSortOrder(String sortOrder) {
        this.sortOrder = sortOrder;
    }

    public Boolean getCountable() {
        return countable;
    }

    public void setCountable(Boolean countable) {
        this.countable = countable;
    }

    public Date getStartTime() {
        return startTime;
    }

    public void setStartTime(Date startTime) {
        this.startTime = startTime;
    }

    public Date getEndTime() {
        return endTime;
    }

    public void setEndTime(Date endTime) {
        this.endTime = endTime;
    }
}
